<template>
  <div>
    <el-container>
      <div class="header">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/' }">反馈管理</el-breadcrumb-item>
          <el-breadcrumb-item><a href="/">用户反馈工单</a></el-breadcrumb-item>
        </el-breadcrumb>
        <!-- <div>
          <el-button type="primary">刷新</el-button>
          <el-button>返回</el-button>
        </div> -->
      </div>
      <div>
        <div class="search">
          <el-input
            class="length right"
            v-model="search.userName"
            size="large"
            clearable
            placeholder="姓名"
          />
          <el-input
            class="length right"
            v-model="search.userPhone"
            size="large"
            clearable
            placeholder="手机号码"
          />
          <el-select
            v-model="search.feedbackStatus"
            class="m-2 right"
            clearable
            placeholder="状态"
            size="large"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
          <el-button class="height" type="primary" @click.native="searchData"
            >查询</el-button
          >
          <el-button class="height">重置</el-button>
        </div>
        <!-- 模态框 -->
        <el-dialog
          v-model="dialogVisible"
          title="工单处理"
          width="30%"
          :before-close="handleClose"
        >
          <span>处理结果反馈</span>
          <el-input
            v-model="result.info"
            :rows="2"
            type="textarea"
            placeholder="请输入处理结果"
          />
          <template #footer>
            <span class="dialog-footer">
              <el-button @click="dialogVisible = false">关闭</el-button>
              <el-button type="primary" @click="submit()"> 提交 </el-button>
            </span>
          </template>
        </el-dialog>
        <!-- 表格 -->
        <el-table
          :data="
            state.tableData.slice(
              (currentPage4 - 1) * pageSize4,
              currentPage4 * pageSize4
            )
          "
        >
          <el-table-column type="selection" width="55" />
          <!-- <el-table-column type="selection" width="55" /> -->
          <el-table-column
            :prop="index"
            :key="index"
            :label="item"
            v-for="(item, index) in tableHeader"
          ></el-table-column>
          <el-table-column label="操作">
            <template #default="scope">
              <el-button
                size="small"
                type="success"
                @click="handleOpen(scope.row)"
                >处理</el-button
              >
              <el-button size="small" type="primary" @click="details(scope.row)"
                >详情</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <el-footer>
        <el-pagination
          v-model:current-page="currentPage4"
          v-model:page-size="pageSize4"
          :page-sizes="[1, 2, 3, 4]"
          :small="small"
          :disabled="disabled"
          :background="background"
          layout="total, sizes, prev, pager, next, jumper"
          v-model:total="allList"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </el-footer>
    </el-container>
  </div>
</template>

<script lang="ts" setup>
import { onBeforeMount, reactive, ref, watch } from "vue";
import { feedbackList, queryList, upload } from "../http/api";
import { useRouter } from "vue-router";
const router = useRouter();
// const userName = ref("");
// const userPhone = ref("");
// const value = ref("");
const options = [
  {
    value: "未处理",
    label: "未处理",
  },
  {
    value: "已处理",
    label: "已处理",
  },
];
var dialogVisible = ref(false);
// 上传处理结果
let result = reactive({
  id: "",
  info: "",
});
const handleOpen = (row: any) => {
  dialogVisible.value = true;
  // console.log(row.id);
  result.id = row.id;
};
const submit = () => {
  dialogVisible.value = false;
  upload(result).then((res) => {
    // console.log("5555555555555", res);
    result.info = "";
  });
};
// 关闭弹窗
const handleClose = () => {
  dialogVisible.value = false;
};

const tableHeader: any = ref({
  id: "反馈单号",
  userName: "用户名",
  userPhone: "手机号码",
  pictureNumber: "图片数量",
  createTime: "反馈时间",
  feedbackStatus: "处理结果",
  feedbackTime: "处理时间",
});
let state = reactive({ tableData: [] });
let allList = ref();
let searchList = {};

// 获取列表数据
const getList = () => {
  feedbackList(searchList)
    .then((res: any) => {
      console.log("res", res);
      if (res.code === 200) {
        state.tableData = res.data.list;
        allList.value = res.data.total;
      }
    })
    .catch((err) => {
      console.log("err.message", err.message);
      state.tableData = [];
    });
};
onBeforeMount(() => {
  getList();
});
// 搜索
let search = reactive({
  userName: "",
  userPhone: "",
  feedbackStatus: "",
});
const searchData = () => {
  queryList(search)
    .then((res: any) => {
      if (res.code === 200) {
        state.tableData = res.data.list;
        allList.value = res.data.total;
      }
    })
    .catch((err) => {
      console.log(err.message);
    });
};

const currentPage4 = ref(1);
const pageSize4 = ref(1);
const small = ref(false);
const background = ref(false);
const disabled = ref(false);
const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`);
  pageSize4.value = val;
  getList();
};
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`);
  currentPage4.value = val;
  getList();
};
// 跳转详情页面
const details = (row: any) => {
  // console.log(row);
  // console.log("row.id", row.id);
  router.push({
    name: "feedbackDetails",
    path: `/home/feedback/feedbackDetails/${row.id}`,
    params: {
      id: row.id,
    },
  });
};
</script>
<style scoped>
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px;
  margin: 10px 0;
}
.length {
  width: 200px;
}
.search {
  display: flex;
  align-items: center;
  margin: 0 0 12px 12px;
  /* overflow: hidden; */
}
.right {
  margin-right: 10px;
}
.height {
  height: 38px !important;
}
</style>